function loadBookNotes(){

    //console.log("1111111111111111")
    //将点击的笔记本li设置为选中状态
    $("#book_list li a").removeClass("checked");
    $(this).find("a").addClass("checked");
    //获取请求参数 bookId
    var bookId = $(this).data("bookId");
    //console.log(bookId);
    //发送ajax请求
    $.ajax({
        url: base_url + "/note/loadnotes.do",
        type: "post",
        data: {"bookId":bookId},
        dataType: "json",
        success:function(result){
            //console.log(result);
            if(result.status == 0){
                var notes = result.data;//获取笔记数组
                //清除原有笔记列表
                $("#note_list").empty();
                for(var i=0;i<notes.length;i++){
                    var noteTitle = notes[i].cn_note_title;
                    var noteId = notes[i].cn_note_id;
                    //拼接成笔记li
                    createNoteLi(noteTitle,noteId)
                }
            }

        },
        error:function(){
            alert("添加笔记列表失败")

        }
    });


}

function createNoteLi(noteTitle,noteId){

    var s_li = '<li class="online">'
    s_li += '<a>'
    s_li += '<i class="fa fa-file-text-o" title="online" rel="tooltip-bottom"></i>'+noteTitle
    s_li += '<button type="button" class="btn btn-default btn-xs btn_position btn_slide_down"><i class="fa fa-chevron-down"></i></button>'
    s_li += '</a>'
    s_li += '<div class="note_menu" tabindex="-1">'
    s_li += '<dl>'
    s_li += '<dt><button type="button" class="btn btn-default btn-xs btn_move" title="移动至..."><i class="fa fa-random"></i></button></dt>'
    s_li += '<dt><button type="button" class="btn btn-default btn-xs btn_share" title="分享"><i class="fa fa-sitemap"></i></button></dt>'
    s_li += '<dt><button type="button" class="btn btn-default btn-xs btn_delete" title="删除"><i class="fa fa-times"></i></button></dt>'
    s_li += '</dl>'
    s_li += '</div>'
    s_li += '</li>';
    //将noteId绑定到li上
    var $li = $(s_li);
    $li.data("noteId",noteId);
    //将li追加到ul中
    $("#note_list").append($li);
}
function load(){
    //获取请求参数
    var noteId = $(this).data("noteId");
    //发送ajax
    $.ajax({
        url: base_url + "/note/load.do",
        type: "post",
        data: {"id": noteId},
        dataType: "json",
        success:function(result){
            //console.log(result);
            if(result.status == 0){
                var noteTitle = result.data.cn_note_title;
                var noteBody = result.data.cn_note_body;
                //设置标题
                $("#input_note_title").val(noteTitle);
                //设置内容
                um.setContent(noteBody);
            }
        },
        error: function(){
            alert("显示笔记详情失败")
        }
    });
}
function addNote(){
    //console.log("111111111111");
    var noteTitle = $("#input_note").val().trim();
    //笔记本id
    var $li = $("#book_list li a.checked").parent();
    var bookId = $li.data("bookId");
    //console.log(noteTitle,bookId);
    //发送ajax
    $.ajax({
        url: base_url + "/note/add.do",
        type: "post",
        data: {"bookId":bookId,"noteTitle":noteTitle,"userId":userId},
        dataType: "json",
        success: function(result){
            if(result.status == 0){
                closeWindows();
                createNoteLi(noteTitle,result.data);
                // console.log(result.data)
            }

        },
        error:function(){
            alert("笔记添加失败")
        }
    });
};